//: CheckoutForm.java 10.09.2008 15:42:37Z apt $
package com.devunion.salon.web.form;

import com.devunion.salon.web.bean.ChequeBean;
import com.devunion.salon.web.bean.TransactionBean;
import com.devunion.salon.web.bean.CashInOutBean;
import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Timoshenko Alexander
 */
public class CheckoutForm extends ActionForm {
    private String hiddenDate;
    private String number;
    private List<ChequeBean> transactions = new ArrayList<ChequeBean>();
    private List<CashInOutBean> cashes = new ArrayList<CashInOutBean>();
    private Boolean isStarted;

    private String selectedEmployee;
    private String selectedCustomer;
    private List<LabelValueBean> employees = new ArrayList<LabelValueBean>();
    private List<LabelValueBean> customers = new ArrayList<LabelValueBean>();

    private Float startDay;
    private Float totalCash;
    private Float totalCredit;
    private Float totalGiftcard;
    private Float totalCheck;

    public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
        //transactions.clear();
        number = null;
        employees.clear();
        customers.clear();
        selectedEmployee = selectedCustomer = null;
        super.reset(actionMapping, httpServletRequest);    //To change body of overridden methods use File | Settings | File Templates.
    }

    public String getHiddenDate() {
        return StringUtils.isBlank(this.hiddenDate) ? String.valueOf(System.currentTimeMillis()) : this.hiddenDate;
    }

    public void setHiddenDate(String hiddenDate) {
        this.hiddenDate = hiddenDate;
    }

    public List<ChequeBean> getTransactions() {
        return transactions;
    }

    public void setTransactions(List<ChequeBean> transactions) {
        this.transactions = transactions;
    }

    public Boolean getIsStarted() {
        return isStarted;
    }

    public void setIsStarted(Boolean started) {
        isStarted = started;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getSelectedEmployee() {
        return selectedEmployee;
    }

    public void setSelectedEmployee(String selectedEmployee) {
        this.selectedEmployee = selectedEmployee;
    }

    public String getSelectedCustomer() {
        return selectedCustomer;
    }

    public void setSelectedCustomer(String selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }

    public List<LabelValueBean> getEmployees() {
        return employees;
    }

    public void setEmployees(List<LabelValueBean> employees) {
        this.employees = employees;
    }

    public List<LabelValueBean> getCustomers() {
        return customers;
    }

    public void setCustomers(List<LabelValueBean> customers) {
        this.customers = customers;
    }    

    public Float getProductTotal() {
        Float result = 0f;
        for (ChequeBean bean : transactions) {
            if (bean.getTransactions() != null) {
                for (TransactionBean transactionBean : bean.getTransactions()) {
                    if(transactionBean.getProduct()!=null || transactionBean.getGiftcardBean()!=null){
                        result+=transactionBean.getTotal();
                    }                    
                }
            }
        }
        return result;
    }

    public Float getServiceTotal() {
        Float result = 0f;
        for (ChequeBean bean : transactions) {
            if (bean.getTransactions() != null) {
                for (TransactionBean transactionBean : bean.getTransactions()) {
                    if(transactionBean.getService()!=null){
                        result+=transactionBean.getTotal();
                    }
                }
            }
        }
        return result;
    }

    public Float getTotalCash() {
        return totalCash;
    }

    public void setTotalCash(Float totalCash) {
        this.totalCash = totalCash;
    }

    public Float getTotalCredit() {
        return totalCredit;
    }

    public void setTotalCredit(Float totalCredit) {
        this.totalCredit = totalCredit;
    }

    public Float getTotalGiftcard() {
        return totalGiftcard;
    }

    public void setTotalGiftcard(Float totalGiftcard) {
        this.totalGiftcard = totalGiftcard;
    }

    public Float getTotalCheck() {
        return totalCheck;
    }

    public void setTotalCheck(Float totalCheck) {
        this.totalCheck = totalCheck;
    }

    public Float getStartDay() {
        return startDay;
    }

    public void setStartDay(Float startDay) {
        this.startDay = startDay;
    }

    public List<CashInOutBean> getCashes() {
        return cashes;
    }

    public void setCashes(List<CashInOutBean> cashes) {
        this.cashes = cashes;
    }
}
